/*
 * Copyright 2025-2026 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package glz.hawk.springboot.jooq.poc;

import org.jooq.codegen.GenerationTool;
import org.jooq.meta.jaxb.*;
import org.jooq.meta.jaxb.Configuration;

/**
 * 编程方式生成代码，对应mysql数据库
 *
 * @author Zhang Peng
 */
public class MysqlGeneratorApplication {

    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration()
            .withJdbc(new Jdbc()
                .withDriver("com.mysql.cj.jdbc.Driver")
                .withUrl("jdbc:mysql://localhost:3306/got")
                .withUser("root")
                .withPassword("password"))
            .withGenerator(new Generator()
                .withName("org.jooq.codegen.JavaGenerator")
                .withDatabase(new Database()
                    .withName("org.jooq.meta.mysql.MySQLDatabase")
                    .withIncludes(".*")      // 包含所有表
                    .withExcludes("")        // 排除规则
                    .withInputSchema("got")) // 数据库名
                .withTarget(new Target()
                    .withPackageName("com.example.mysql")  // 生成的包名
                    .withDirectory("springboot/springboot-jooq/src/generated/java")));    // 输出目录

        GenerationTool.generate(configuration);
    }
}
